package cn.tradewin.pmp.pages.test;

import java.util.List;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import cn.tradewin.common.model.SelectOption;
import cn.tradewin.common.util.XmemcachedKeys;
import cn.tradewin.pmp.services.MasterService;

import com.whalin.MemCached.MemCachedClient;

public class AddMasterData {

	@Property
	@Persist(PersistenceConstants.FLASH)
	private String label;
	
	@Property
	@Persist(PersistenceConstants.FLASH)
	private String value;
	
	@Inject
	MasterService service;
	
	@Inject
	MemCachedClient client;
	
	void onSuccess() {
		List<SelectOption> countries = service.getSupportCountry();
		for (SelectOption o : countries) {
			if (o.getValue().equalsIgnoreCase(value)) {
				return;
			}
		}
		countries.add(new SelectOption(label, value));
		client.replace(XmemcachedKeys.CACHED_SUPPORTED_COUNTRY, countries);
	}
}
